package com.tanhua.app.controller;

import com.tanhua.app.controllerservice.UserService;
import com.tanhua.domain.db.User;
import com.tanhua.domain.db.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping(name = "根据手机号查询用户",value = "/findByPhone")
    public ResponseEntity findByPhone(String phone){
        return userService.findByPhone(phone);
    }


    @PostMapping(name = "保存用户",value = "/saveUser")
    public ResponseEntity saveUser(@RequestBody User user){
        return userService.saveUser(user);
    }


    @PostMapping(name = "手机号发短信",value = "/login")
    public ResponseEntity login(@RequestBody Map<String,String> map){
        String phone = map.get("phone");
        return userService.login(phone);
    }


    @PostMapping(name = "用户登录",value = "/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map<String,String> map){

        //1 获取手机号和验证码
        String phone = map.get("phone");
        String verificationCode = map.get("verificationCode");
        return userService.loginVerification(phone,verificationCode);
    }


    @PostMapping(name = "用户完善--上半部分",value = "/loginReginfo")
    public ResponseEntity loginReginfo(@RequestHeader("Authorization") String token, @RequestBody UserInfo userInfo){
        return userService.loginReginfo(token,userInfo);
    }


    @PostMapping(name = "用户完善--下半部分",value = "/loginReginfo/head")
    public ResponseEntity head(@RequestHeader("Authorization") String token,MultipartFile headPhoto) throws IOException {
        return userService.head(token,headPhoto);
    }








}
